package io.github.iogogogo.kafka.consumer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

/**
 * Created by tao.zeng on 2024/12/25.
 */
@Slf4j
@Component
@ConditionalOnProperty(name = "spring.kafka.first.enabled", havingValue = "true")
public class KafkaConsumer {

    @KafkaListener(topics = "topic_order_cancel", groupId = "group_id_order_cancel", containerFactory = "firstKafkaListenerContainerFactory")
    public void listenOrder(String message, Acknowledgment acknowledgment) {
        try {
            // 业务处理
            log.info("收到kafka message: {}", message);
        } finally {
            acknowledgment.acknowledge();
        }
    }
}
